/*
 * demo.c
 *
 *  Created on: 2018年10月9日
 *  Author: Degang.Wu (windragon@126.com)
 *  Desc:
 */

#include <stdlib.h>
#include "bw_net_cfg.h"
#include <net/if.h>

#if 0
#define BW_INFO		printf

int main(int argc, char **argv) 
{
	stNetParam np;
	const char* ethname = "eth0";

	BW_INFO("%s\n", bw_net_get_version());

	/*char if_name[50] = {0};
	struct if_nameindex *head, *ifni; 
	
	ifni = if_nameindex(); 
	head = ifni; 
	if (head == NULL) 
	{ 
		perror("if_nameindex()"); 
		exit(EXIT_FAILURE); 
	} 
	while (ifni->if_index != 0) 
	{ 
		printf("Interfece %d : %s\n", ifni->if_index, ifni->if_name); 
		ifni++; 
	} 

	if_freenameindex(head);
    head = NULL;
    ifni = NULL;
    */
	
	//服务启动后，初始化调用
	/*bw_net_init_cfg();
	*/

	//获取参数
	bw_net_getparams(ethname, &np);
	char mac_s[64];
	snprintf(mac_s, sizeof(mac_s), "%02x:%02x:%02x:%02x:%02x:%02x",
			np.mac[0] & 0xff, np.mac[1] & 0xff, np.mac[2] & 0xff,
			np.mac[3] & 0xff, np.mac[4] & 0xff, np.mac[5] & 0xff);
	BW_INFO("before eth:%s, ip:%s, netmask:%s, gateway:%s, bootproto:%s, mac:%s, idx:%d\n",
			np.name, np.ipaddr, np.netmask, np.gateway, np.bootproto, np.mac_str, np.ethid);


	//设置参数
	
	int ret = bw_net_set_cfg(ethname, "192.168.80.100", "255.255.255.0", "192.168.80.1");
	if (ret < 0)
	{
		BW_INFO("set failed\n");
	}

	bw_net_set_mac(ethname, "00:0C:18:EF:FF:E9");

	/*
	bw_net_getparams(ethname, &np);
	snprintf(mac_s, sizeof(mac_s), "%02x:%02x:%02x:%02x:%02x:%02x",
			np.mac[0] & 0xff, np.mac[1] & 0xff, np.mac[2] & 0xff,
			np.mac[3] & 0xff, np.mac[4] & 0xff, np.mac[5] & 0xff);
	BW_INFO("after eth:%s, ip:%s, netmask:%s, gateway:%s, bootproto:%s, mac:%s, idx:%d\n",
			np.name, np.ipaddr, np.netmask, np.gateway, np.bootproto, np.mac_str, np.ethid);

	// igmp version
	bw_net_set_igmp(BW_NET_IGMP_V2);
	system("cat /proc/net/igmp");
	return 0;
	*/
}
#endif
